﻿using BaoVeThanhDia.GamePlay.Monsters;
using BaoVeThanhDia.Sound;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;

namespace BaoVeThanhDia.GamePlay.Towers
{
    public abstract class Tower
    {
        protected int Level;
        protected int Type;
        protected Texture2D Image, ImageBuffed;
        protected float Price, PriceBought;
        protected float PhysicDame;
        protected float MagicDame;
        protected float Range;
        protected float Speed;
        protected float countEffect;// xác suất xuất hiện hiệu ứng or chỉ số hiệu 
        protected string Effect;
        protected Vector2 Position;
        protected Vector2 Index;
        protected float scale;
        protected int ValueBuff;
        protected List<Weapon> weapons;
        protected CustomSoundEffect sound;
        public void setEffect(string effect)
        {
            Effect = effect;
        }
        public void setIndex(Vector2 index)
        {
            Index = index;
            int tempSize = 128;
            Position = new Vector2(tempSize * index.Y, tempSize * index.X);
        }
        public float getRange() { return Range; }
        public int getType() { return Type; }
        public int getLevel() { return Level; }
        public Vector2 getIndex() { return Index; }
        public void setLevel(int i, ContentManager content, int nhanh) { Level = i; Type = nhanh; Load(content); }
        public abstract void setLevel(int level, int nhanh);
        public void DrawWeapon(ContentManager cont, SpriteBatch sprite)
        {
            foreach (Weapon weapon in weapons)
            {
                weapon.DiChuyen();
                if (weapon.getImage() == null)
                {
                    weapon.Load(cont);
                }
                else weapon.Draw(sprite);
            }
            for (int i = 0; i < weapons.Count; i++)
            {
                if (!weapons[i].getEnable())
                {
                    weapons.RemoveAt(i);
                }
            }
        }
        public abstract void Load(ContentManager content);
        public abstract void Draw(ContentManager cont, SpriteBatch sprite);
        public abstract void Ban();
        public abstract void setelement();
        public abstract void OptionDraw(SpriteBatch sprite, Vector2 posi, Vector2 dolech, float scale, bool isTouch);
        public abstract float getPriceUpGrade(int level, int type);
        public abstract void DrawPictureUpGrade(int level, int type, ContentManager cont, SpriteBatch sprite, Vector2 posi);
        public float getMagicDame() { return MagicDame; }
        public float getPhysicDame() { return PhysicDame; }
        public float getSpeed() { return Speed; }
        public Vector2 getPosition() { return Position; }
        public void GetBuff(List<Tower> towers)
        {
            if (this.GetType() == typeof(SoulTower)) ValueBuff = 0;
            else
            {
                foreach (Tower tower in towers)
                {
                    if (tower.GetType() == typeof(SoulTower) && Vector2.Distance(tower.getPosition(), Position) <= 128 * tower.getRange())
                    {
                        ValueBuff = (int)tower.getPhysicDame() > ValueBuff ? (int)tower.getPhysicDame() : ValueBuff;
                    }
                }
            }
        }
        public float getPrice() { return Price; }
        public float getPriceBought() { return PriceBought; }

    }
}
